/**   
 * @Title: GetHemaiListCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.hemaicenter 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-12-8 上午10:22:47  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.hemaicenter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.sportteryfootball.FootballHemaiListItemInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: GetHemaiListCommunicater
 * @Description: lotid int(10) 彩种id 必填 排列3:5 expect varchar(200) 期号 必填 pageno int(10) 页码 选填 pagesize int(10) 每页显示数目 选填 sortfield varchar(200) 排序区域 选填 sortorder varchar(10) 排序方式
 *               选填：asc 升序 Desc 降序 返回参数说明 state int(1) 执行状态 message varchar(200) 状态解释 id varchar(100) 方案id proid varchar(100) 方案编号 playtype int(10) 玩法 username varchar(100) 用户名
 *               zhanji int(10) 战绩 allmoney int(10) 方案总金额 renqi int(10) 人气（进度） anumber int(10) 方案总分数 hnumber int(10) 已购买份数 setorder int(1) 是否置顶 0：非置顶 其它：置顶 onemoney int(10) 每份金额
 * 
 * @author: City Jiangsy@500wan.com
 * @date: 2011-12-8 上午10:22:47
 * 
 */
public class GetHemaiListCommunicater extends ServerCommunicater {
	private ArrayList<FootballHemaiListItemInfo> listHemaiListItemInfo = new ArrayList<FootballHemaiListItemInfo>();

	private String msgServer; // 服务器信息
	private boolean isSucceed = false;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	public boolean isGetHemaiListSucceed(String lotId, String expect, int sortCode, int sorterCode, int pageSize, int pageNo) throws ClientProtocolException, IOException,
			ParserConfigurationException, SAXException {

		String strSorter = null;
		if (sorterCode == 1) {
			strSorter = Key.KEY_ASC;
		} else {
			strSorter = Key.KEY_DESC;
		}
		String strSort = null;

		if (sortCode == 0) {
			strSort = Key.KEY_RENQI;
		} else if (sortCode == 1) {
			strSort = Key.KEY_ALLMONEY;
		} else if (sortCode == 2) {
			strSort = Key.KEY_ZHANJI;
		} else {
			strSort = Config.NULLMARK;
		}

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, "10075"));
		list.add(mapItem(Key.KEY_LOTID, lotId));
		list.add(mapItem(Key.KEY_SORTFIELD, strSort));
		list.add(mapItem(Key.KEY_SORTORDER, strSorter));
		list.add(mapItem(Key.KEY_PAGESIZE, Integer.toString(pageSize)));
		list.add(mapItem(Key.KEY_PAGENO, Integer.toString(pageNo)));
		list.add(mapItem(Key.KEY_EXPECT, expect));
		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setMsgServer(super.getErrorMSG());
		if (super.getState() == 100) {
			isSucceed = true;
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}

	// 返回合买信息
	public ArrayList<FootballHemaiListItemInfo> getLotteryInfoList() {
		listHemaiListItemInfo.clear();
		int count = super.getListResult().size();
		for (int i = 0; i < count; i++) {
			FootballHemaiListItemInfo hemaiListItemInfo = new FootballHemaiListItemInfo();
			hemaiListItemInfo.setId(super.getListResult().get(i).get(Key.KEY_ID));
			hemaiListItemInfo.setProId(super.getListResult().get(i).get(Key.KEY_PROID));
			hemaiListItemInfo.setPlayType(super.getListResult().get(i).get(Key.KEY_PLAYTYPE));
			hemaiListItemInfo.setUserName(super.getListResult().get(i).get(Key.KEY_USERNAME));
			hemaiListItemInfo.setZhanji(super.getListResult().get(i).get(Key.KEY_ZHANJI));
			hemaiListItemInfo.setAllMoney(super.getListResult().get(i).get(Key.KEY_ALLMONEY));
			hemaiListItemInfo.setAllNum(super.getListResult().get(i).get(Key.KEY_ANUMBER));
			hemaiListItemInfo.setSellNum(super.getListResult().get(i).get(Key.KEY_HNUMBER));
			hemaiListItemInfo.setJindu(super.getListResult().get(i).get(Key.KEY_RENQI));
			hemaiListItemInfo.setEachMoney(super.getListResult().get(i).get(Key.KEY_ONEMONEY));
			hemaiListItemInfo.setSetOrder(super.getListResult().get(i).get(Key.KEY_SETORDER));
			listHemaiListItemInfo.add(hemaiListItemInfo);

		}
		return listHemaiListItemInfo;
	}

	/**
	 * @Title: mapItem
	 * @Description: (工具类,用于构建AraayList单条内容)
	 * @param @param name 参数名
	 * @param @param value 参数值
	 * @param @return map
	 * @return HashMap<String,String> 返回类型
	 * @throws
	 */
	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
